package br.com.fiap.trabalho.dao;

import javax.persistence.EntityManager;

public class JPADAO<T> {

	protected EntityManager em;
	
	public JPADAO(EntityManager em){
		this.em = em;
	}
	
	public void closeConection(){
		if (this.em != null ){
			em.close();
		}
	}
	public T persist (T object){
		em.getTransaction().begin();
		em.persist(object);
		em.getTransaction().commit();
		return object;
	}
	
	public boolean delete (T entity){
		em.getTransaction().begin();
		em.remove(entity);
		em.getTransaction().commit();
		return true;
	}
	
	public T merge (T entity){
		em.getTransaction().begin();
		em.merge(entity);
		em.getTransaction().commit();
		
		return entity;
	}
		
}
